package org.dey.controller;

import org.dey.entity.Result;
import org.dey.pojo.PageVo;
import org.dey.pojo.QuestionBank;
import org.dey.service.QuestionBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class QuestionBankController {

    @Autowired
    QuestionBankService questionBankService;

    //    打开管理页面显示数据
    @PostMapping("questionBank.action/{pagecurrent}/{pagesize}")
    public PageVo<QuestionBank> questionnairelist(@RequestBody QuestionBank questionBank, @PathVariable int pagecurrent, @PathVariable int pagesize){

        PageVo<QuestionBank> queryquestionBank = questionBankService.queryQuestionBank(questionBank, pagecurrent, pagesize);
        return queryquestionBank;
    }

    //添加
    @PostMapping("questionBank.action")
    public Result addquestionnaire(@RequestBody QuestionBank questionBank){

        Result insertquestionBank = questionBankService.insertQuestionBank(questionBank);

        return insertquestionBank;
    }

    //删除
    @DeleteMapping("questionBank.action/{id}")
    public Result delquestionBankbyid(@PathVariable int id){

        Result delquestionBank = questionBankService.deleteQuestionBank(id);

        return delquestionBank;
    }

    //修改先根据id查到该数据
    @GetMapping("questionBank.action/{id}")
    public QuestionBank queryquestionBankbyid(@PathVariable Integer id){

        QuestionBank queryquestionBankbyid = questionBankService.queryQuestionBankByid(id);

        return queryquestionBankbyid;
    }

    //根据id修改
    @PutMapping("questionBank.action")
    public Result updatequestionBankbyid(@RequestBody QuestionBank questionBank){

        Result updatequestionBankbyid = questionBankService.updateQuestionBank(questionBank);

        return updatequestionBankbyid;
    }
}
